{% block sw_settings_mailer_index %}
<sw-page class="sw-settings-mailer">

    {% block sw_settings_mailer_smart_bar_header %}
    <template #smart-bar-header>
        {% block sw_settings_mailer_smart_bar_header_title %}
        <h2>
            {% block sw_settings_mailer_smart_bar_header_title_text %}
            {{ $tc('sw-settings.index.title') }}
            <mt-icon
                name="regular-chevron-right-xs"
                size="12px"
            />
            {{ $tc('sw-settings-mailer.general.textHeadline') }}
            {% endblock %}
        </h2>
        {% endblock %}
    </template>
    {% endblock %}

    {% block sw_settings_mailer_smart_bar_actions %}
    <template #smart-bar-actions>
        {% block sw_settings_mailer_actions_save %}
        <sw-button-process
            :is-loading="isLoading"
            :process-success="isSaveSuccessful"
            variant="primary"
            @update:process-success="onSaveFinish"
            @click="saveMailerSettings"
        >
            {{ $tc('sw-settings-mailer.general.buttonSave') }}
        </sw-button-process>
        {% endblock %}
    </template>
    {% endblock %}

    {% block sw_settings_mailer_content %}
    <template #content>
        <sw-card-view>
            <sw-skeleton v-if="isLoading" />

            <mt-card
                v-else
                position-identifier="sw-settings-mailer-configuration"
                :is-loading="isLoading"
                :title="$tc('sw-settings-mailer.mailer-configuration.card-title')"
            >

                {% block sw_settings_mailer_first_configuration %}
                <div
                    v-if="isFirstConfiguration"
                    class="sw-settings-mailer__first-configuration"
                >
                    {% block sw_settings_mailer_first_configuration_headline %}
                    <h4 class="sw-settings-mailer__headline">
                        <strong>
                            {{ $tc('sw-settings-mailer.first-configuration.headline') }}
                        </strong>
                    </h4>
                    {% endblock %}

                    {% block sw_settings_mailer_first_configuration_description %}
                    <p>
                        {{ $tc('sw-settings-mailer.first-configuration.description') }}
                    </p>
                    {% endblock %}
                </div>
                {% endblock %}

                {% block sw_settings_mailer_headline_agent %}
                <p class="sw-settings-mailer__headline">
                    {{ $tc('sw-settings-mailer.mailer-configuration.agent') }}
                </p>
                {% endblock %}

                <div class="sw-settings-mailer__radio-selection">
                    {% block sw_settings_mailer_agent_options %}
                    <mt-select
                        v-model="mailerSettings['core.mailerSettings.emailAgent']"
                        :options="emailAgentOptions"
                    />

                    <sw-radio-field
                        v-if="mailerSettings['core.mailerSettings.emailAgent'] === 'local'"
                        v-model:value="mailerSettings['core.mailerSettings.sendMailOptions']"
                        :options="emailSendmailOptions"
                    />
                    {% endblock %}
                </div>

                <p v-html="$tc('sw-settings-mailer.helpText')"></p>

                <mt-switch
                    v-if="!isSmtpMode"
                    v-model="mailerSettings['core.mailerSettings.disableDelivery']"
                    :label="$tc('sw-settings-mailer.card-smtp.disable-delivery')"
                />
            </mt-card>

            {% block sw_settings_mailer_smtp %}
            <mt-card
                v-if="isSmtpMode"
                position-identifier="sw-settings-mailer-smtp-settings"
                :is-loading="isLoading"
                title="SMTP server"
                class="sw-settings-mailer__input-fields"
            >

                {% block sw_settings_mailer_smtp_settings %}
                <sw-settings-mailer-smtp
                    :mailer-settings="mailerSettings"
                    :host-error="smtpHostError"
                    :port-error="smtpPortError"
                    @host-changed="resetSmtpHostError"
                    @port-changed="resetSmtpPortError"
                />
                {% endblock %}

            </mt-card>
            {% endblock %}
        </sw-card-view>
    </template>
    {% endblock %}
</sw-page>
{% endblock %}
